package rhinestone.Model;

import java.util.HashMap;
import java.util.Iterator;
import java.io.Serializable;

/**
 * This class represents the Lease.
 * It goes in the LeaseContainer.
 */

public class Lease implements Serializable {
	private static int leaseID = 0;
	private int id;
    private Staff staff;
    private Customer customer;
    private String status;
    private HashMap<Machinery, Integer> machinery;

    public Lease(Staff staff, Customer customer){
		id = ++leaseID;
        this.staff = staff;
        this.customer = customer;
        machinery = new HashMap<Machinery, Integer>();
    }
    public void addMachinery(Machinery item, int period){
        machinery.put(item, period);
    }

	public void removeMachinery(Machinery item) {
		machinery.remove(item);
	}

	public int getMachineryCount() {
		return machinery.size();
	}

	public int getId() {
		return id;
	}

    public double getTotalPrice(){
        
		// ...
		return 0;
        
    }
    public Staff getEmployee(){
        return staff;
    }
    public Customer getCustomer(){
        return customer;
    }
    public String getStatus(){
        return status;
    }

	public void changeMachineryStatus() {
		Iterator<Machinery> it = machinery.keySet().iterator();
		while(it.hasNext()) {
			Machinery m = it.next();
			m.setStatus(Machinery.ON_LEASE);
		}
	}

	@Override
	public String toString() {
		String output = "----------------------------------";
		output += "\n\tMACHINERY:";
		Iterator<Machinery> it = machinery.keySet().iterator();
		while(it.hasNext()) {
			Machinery m = it.next();
			int amount = machinery.get(m);
			output += "\n\t" + m.getName() + " ("+m.getBarcode()+"). PERDIOD: " + amount + " days.";
		}
		output += "\n----------------------------------";
		return output;
	}
}
